<?php
/**
 * @package    Joomla.Tutorials
 * @subpackage Components
 * @link http://docs.joomla.org/Developing_a_Model-View-Controller_Component_-_Part_1
 * @license    GNU/GPL
*/
 
// no direct access
 
defined( '_JEXEC' ) or die( 'Restricted access' );
 
jimport( 'joomla.application.component.view');
jimport( 'joomla.filesystem.path' );

jimport( 'joomla.database.database' );
include JPATH_COMPONENT.DS.'functions.php';
/**
 * HTML View class for the HelloWorld Component
 *
 * @package    HelloWorld
 */
 
class wotclanViewdelete extends JView
{
    function display($tpl = null)
    {
    	if (JFactory::getUser()->authorise('core.add', 'com_wotclan')) 
      {
      	if ($_GET["type"] == "utank") {
      		$db =& JFactory::getDbo();
        	$query = $db->getQuery(true);
        	$greeting = "Les tanks de la DB!";
        	$this->assignRef( 'greeting', $greeting );
        	parent::display($tpl);
   	    	if($_POST["account"] != ""){
   	    		echo "l'utilisateur n'est pas identifier ...";
   	    	} else {
   	    		$query="SELECT * FROM `#__wotclan_account` WHERE `uniqid`='".$_GET["account"]."'";
   	    		$db->setQuery($query);
      			$db->query();
      			$num_rows = $db->getNumRows();
      			$rows = $db->loadObjectList();
      			if ($num_rows<1){
      				echo "Prob ...";
      				echo $query;
      			} else if ($num_rows==0) {
      				echo "another prob ...";
      			} else {
      				if (preg_match("/".$_GET["tankid"]."\|/",$rows[0]->tanks)){
      					$newstring=preg_replace("/".$_GET["tankid"]."\|/","",$rows[0]->tanks);
      					echo "premier match, new string : " . $newstring ;
      					
      				} else if (preg_match("/\|".$_GET["tankid"]."/",$rows[0]->tanks)){
								$newstring=preg_replace("/\|".$_GET["tankid"]."/","",$rows[0]->tanks);
								echo "deuxieme match, new string : " . $newstring ;
			  			} else {
			  				$newstring=preg_replace("/".$_GET["tankid"]."/","",$rows[0]->tanks);
			  				echo "troisieme match, new string : " . $newstring ;
			  			}
			  			$query2 = $db->getQuery(true);
			  			$query2="UPDATE `#__wotclan_account` SET `tanks`='".$newstring."' WHERE `uniqid`='".$_GET["account"]."';";
			  			
   	    			$db->setQuery($query2);
      				$db->query();
      				echo "<h1>newsting= ".$newstring." query : $query2</h1>";
      	 	 }
   	    	}
   	    	if($_GET["tankid"] == ""){
   	    		echo "le tank n'est pas identifier ...";
   	    	}
   	    }
   	    if ($_GET["type"] == "replay") {
   	    	if($_GET["id"] == ""){
   	    		echo "Le replay n'est pas identifer ...";
   	    		
   	    	} else {
   	    		$db =& JFactory::getDbo();
        		$query = $db->getQuery(true);
        		$greeting = "Effacer un replay";
        		$this->assignRef( 'greeting', $greeting );
        		parent::display($tpl);
   	    		$query1="SELECT * FROM `#__wotclan_replays` WHERE `uniqid`='".$_GET["id"]."'";
   	    		$db->setQuery($query1);
      			$db->query();
			$num_rows = $db->getNumRows();
      			$rows = $db->loadObjectList();






   	    		$query="DELETE FROM `#__wotclan_replays` WHERE `uniqid`='".$_GET["id"]."'";
   	    		$db->setQuery($query);
      			$db->query();
      			unlink(JPATH_BASE.DS."media".DS."wotclan".DS."replays".DS.$rows[0]->file);
   	    		
   	    	}
   	    	
   	    }
		//		header('Location: ' . $_SERVER['HTTP_REFERER']);	
				
      }
    
    }
}


